package com.example.springdemo.Controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.springdemo.entity.Orderdetail;
import com.example.springdemo.entity.Productreviews;
import com.example.springdemo.service.IProductreviewsService;
import com.example.springdemo.utils.PassToken;
import com.example.springdemo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 商品评论Controller
 * 
 * @author ruoyi
 * @date 2025-06-08
 */
@RestController
@RequestMapping("/system/productreviews")
public class ProductreviewsController
{
    @Autowired
    private IProductreviewsService productreviewsService;

    /**
     * 查询商品评论列表
     */
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Productreviews productreviews)
    {
//        System.out.println(productreviews.getDetailid());
        return ResponseResult.createBySuccess(200,productreviewsService.selectProductreviewsList(productreviews),"获取成功");
//        startPage();
//        List<Productreviews> list = productreviewsService.selectProductreviewsList(productreviews);
//        return getDataTable(list);
    }

    /**
     * 导出商品评论列表
     */
//
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Productreviews productreviews)
//    {
//        List<Productreviews> list = productreviewsService.selectProductreviewsList(productreviews);
//        ExcelUtil<Productreviews> util = new ExcelUtil<Productreviews>(Productreviews.class);
//        util.exportExcel(response, list, "商品评论数据");
//    }
    @PassToken
    @GetMapping(value = "/{reviewid}")
    public ResponseResult getInfo(@PathVariable("reviewid") String reviewid)
    {
        Productreviews productreviews = productreviewsService.selectProductreviewsByReviewid(reviewid);
        return ResponseResult.createBySuccess(200,productreviews,"查询成功");
    }

    @PassToken
    @GetMapping(value = "/productid/{productid}")
    public ResponseResult getInfo1(@PathVariable("productid") String productid)
    {
        List<Productreviews> productreviews = productreviewsService.selectCommentBygid(productid);
        return ResponseResult.createBySuccess(200,productreviews,"查询成功");
    }

    /**
     * 新增商品评论
     */
    @PassToken
    @PostMapping
    public ResponseResult add(@RequestBody Productreviews productreviews)
    {
        int i = productreviewsService.insertProductreviews(productreviews);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "添加成功");
        } else {
            return ResponseResult.createByFail(200, "添加失败");
        }
    }

    /**
     * 修改商品评论
     */
    @PassToken
    @PutMapping
    public ResponseResult edit(@RequestBody Productreviews productreviews)
    {
        int i = productreviewsService.updateProductreviews(productreviews);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "更新成功");
        } else {
            return ResponseResult.createByFail(200, "更新失败");
        }
    }


    @PassToken
	@DeleteMapping("/{reviewids}")
    public ResponseResult remove(@PathVariable String[] reviewids)
    {
        int i = productreviewsService.deleteProductreviewsByReviewids(reviewids);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "删除成功");
        } else {
            return ResponseResult.createByFail(200, "删除失败");
        }
    }
}
